<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                template="./template.xhtml">

    <ui:define name="title">
        Kết quả bóng đá cập nhật
    </ui:define>

    <ui:define name="content">
        <h:form>
            <p:poll id="p1" interval="30" listener="#{liveSoccerResult.test()}" update="liveMatch" />
            <p:panel header="Các trận đấu đang diễn ra">
                <p:dataTable id="liveMatch" value="#{liveSoccerResult.liveMatches}" var="lMatch" resizableColumns="true"
                             rendered="true"> 
                    <p:column>  
                        <f:facet name="header">  
                            <h:outputText value="Giải đấu" />  
                        </f:facet>  
                        <h:outputText value="#{lMatch.idGiaiDau.tenGiaiDau}" />  
                    </p:column>

                    <p:column>  
                        <f:facet name="header">  
                            <h:outputText value="Ngày/giờ" />  
                        </f:facet>  
                        <h:outputText value="#{lMatch.gioThiDau}">
                            <f:convertDateTime pattern="dd/MM/yyyy hh:mm" />
                        </h:outputText>
                    </p:column>
                    
                    <p:column>  
                        <f:facet name="header">  
                            <h:outputText value="Phút thi đấu" />  
                        </f:facet>  
                        <h:outputText value="#{lMatch.phutThiDau}" />  
                    </p:column>

                    <p:column>  
                        <f:facet name="header">  
                            <h:outputText value="Đội chủ" />  
                        </f:facet>  
                        <h:outputText value="#{lMatch.tenDoiChu} "/>  
                    </p:column>

                    <p:column>  
                        <f:facet name="header">  
                            <h:outputText value="Tỷ số" />  
                        </f:facet>  
                        <h:outputText value="#{lMatch.soBanThangDoiChu.toString()} - #{lMatch.soBanThangDoiKhach.toString()} "/>    
                    </p:column>

                    <p:column>  
                        <f:facet name="header">  
                            <h:outputText value="Đội khách" />  
                        </f:facet>  
                        <h:outputText value="#{lMatch.tenDoiKhach} "/> 
                    </p:column>
                    
                    <p:column>  
                        <f:facet name="header">  
                            <h:outputText value="Mã Trận" />  
                        </f:facet>  
                        <h:outputText value="#{lMatch.matchCode} "/> 
                    </p:column>
                    
                    <p:column>  
                        <f:facet name="header">  
                            <h:outputText value="Xem chi tiết" />  
                        </f:facet>  
                        <p:commandLink action="RateOfSoccer" ajax="false">
                            Chi tiết
                            <f:param name="id" value="#{lMatch.id}"/>
                            <f:param name="match" value="#{lMatch.tenDoiChu.toString()} - #{lMatch.tenDoiKhach.toString()}"/>
                        </p:commandLink>
                    </p:column>
                    
                    <p:column>  
                        <f:facet name="header">  
                            <h:outputText value="Cập nhật trạng thái" />  
                        </f:facet>  
                        <p:commandButton actionListener="#{liveSoccerResult.update2PlayedMatch}" ajax="false" value="Cập nhật">
                            <f:param name="id" value="#{lMatch.id}"/>
                        </p:commandButton>
                    </p:column>

                </p:dataTable>
            </p:panel>
            <p:poll id="p2" interval="30" listener="#{liveSoccerResult.updateCommingMatch()}" update="commingMatch" />
            <p:panel header="Các trận đấu sắp diễn ra">
                <p:dataTable id="commingMatch" value="#{liveSoccerResult.commingMatches}" var="cMatch" resizableColumns="true"
                             paginator="true" rows="20"
                             paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
                             rowsPerPageTemplate="20,40,60" rendered="true"> 

                    <p:column>  
                        <f:facet name="header">  
                            <h:outputText value="Giải đấu" />  
                        </f:facet>  
                        <h:outputText value="#{cMatch.idGiaiDau.tenGiaiDau}" />  
                    </p:column>

                    <p:column>  
                        <f:facet name="header">  
                            <h:outputText value="Ngày/giờ" />  
                        </f:facet>  
                        <h:outputText value="#{cMatch.gioThiDau}">
                            <f:convertDateTime pattern="dd/MM/yyyy hh:mm" />
                        </h:outputText>
                    </p:column>

                    <p:column>  
                        <f:facet name="header">  
                            <h:outputText value="Trận đấu" />  
                        </f:facet>  
                        <b><h:outputText value="#{cMatch.tenDoiChu.toString()} - #{cMatch.tenDoiKhach.toString()}" /></b>
                    </p:column>

                    <p:column>  
                        <f:facet name="header">  
                            <h:outputText value="Chủ" />  
                        </f:facet>  
                        <b><h:outputText value="#{cMatch.keoChauAList.get(0).chuAnMat}" /></b>
                    </p:column>

                    <p:column>  
                        <f:facet name="header">  
                            <h:outputText value="Tỷ lệ" />  
                        </f:facet>  
                        <b><h:outputText value="#{cMatch.keoChauAList.get(0).tyLeChap}" /></b>
                    </p:column>

                    <p:column>  
                        <f:facet name="header">  
                            <h:outputText value="Khách" />  
                        </f:facet>  
                        <b><h:outputText value="#{cMatch.keoChauAList.get(0).khachAnMat}" /></b>    
                    </p:column>
                    
                    <p:column>  
                        <f:facet name="header">  
                            <h:outputText value="Mã Trận" />  
                        </f:facet>  
                        <h:outputText value="#{cMatch.matchCode} "/> 
                    </p:column>

                    <p:column>  
                        <f:facet name="header">  
                            <h:outputText value="Xem chi tiết" />  
                        </f:facet>  
                        <p:commandLink action="RateOfSoccer" ajax="false">
                            Chi tiết
                            <f:param name="id" value="#{cMatch.id}"/>
                            <f:param name="match" value="#{cMatch.tenDoiChu.toString()} - #{cMatch.tenDoiKhach.toString()}"/>
                        </p:commandLink>
                    </p:column>

                </p:dataTable>
            </p:panel>
            <p:poll id="p3" interval="30" listener="#{liveSoccerResult.updatePlayedMatch()}" update="playedMatch" />
            <p:panel header="Các trận đấu đã diễn ra">
                <p:dataTable id="playedMatch" value="#{liveSoccerResult.playedMatches}" var="pMatch" resizableColumns="true"
                             paginator="true" rows="20"  
                             paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
                             rowsPerPageTemplate="20,40,60" rendered="true"> 
                    <p:column>  
                        <f:facet name="header">  
                            <h:outputText value="Giải đấu" />  
                        </f:facet>  
                        <h:outputText value="#{pMatch.idGiaiDau.tenGiaiDau}" />  
                    </p:column>

                    <p:column>  
                        <f:facet name="header">  
                            <h:outputText value="Ngày/giờ" />  
                        </f:facet>  
                            <h:outputText value="#{pMatch.gioThiDau}">
                                <f:convertDateTime pattern="dd/MM/yyyy hh:mm" />
                            </h:outputText>
                    </p:column>

                    <p:column>  
                        <f:facet name="header">  
                            <h:outputText value="Đội chủ" />  
                        </f:facet>  
                        <b><h:outputText value="#{pMatch.tenDoiChu}"/></b>
                    </p:column>

                    <p:column>  
                        <f:facet name="header">  
                            <h:outputText value="Tỷ số" />  
                        </f:facet>  
                        <b><h:outputText value="#{pMatch.soBanThangDoiChu.toString()} - #{pMatch.soBanThangDoiKhach.toString()} " /></b>
                    </p:column>

                    <p:column>  
                        <f:facet name="header">  
                            <h:outputText value="Đội khách" />  
                        </f:facet>  
                        <b><h:outputText value="#{pMatch.tenDoiKhach.toString()}"/></b>
                    </p:column>
                    
                    <p:column>  
                        <f:facet name="header">  
                            <h:outputText value="Mã Trận" />  
                        </f:facet>  
                        <h:outputText value="#{pMatch.matchCode} "/> 
                    </p:column>

                </p:dataTable>
            </p:panel>
        </h:form>
    </ui:define>

</ui:composition>
